#ifndef TOOL_BUTTON_H

#define TOOL_BUTTON_H
#define ICON_UP_SIZE 32
#define ICON_OVER_SIZE 34
#define ICON_DOWN_SIZE 30

#include <QMouseEvent>
#include <QPushButton>
#include <QSize>
#include <QEvent>

class ToolButton: public QPushButton
{
	Q_OBJECT

public:

	ToolButton(QWidget * parent = 0): QPushButton(parent)
	{
		connect(this, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool)));
	};

	~ToolButton(){};

protected:

	void changeEvent ( QEvent * _event )
	{
		if (_event->type() == QEvent::EnabledChange)
		{
			if (isEnabled())
			{
				setEnabledSkin();
			}
			else
			{
				setDisabledSkin();
			}
		}
	}

	void mousePressEvent(QMouseEvent* e)
	{
		QPushButton::mousePressEvent(e);
		if (isEnabled())
		{
			setIconSize(QSize(ICON_DOWN_SIZE, ICON_DOWN_SIZE));
		}
	};

	void enterEvent ( QEvent * event )
	{
		if (!isEnabled())
		{
			return;
		}

		if (!this->isChecked())
		{
			setIconSize(QSize(ICON_OVER_SIZE, ICON_OVER_SIZE));
		}
	};

	void leaveEvent ( QEvent * event )
	{
		if (!isEnabled())
		{
			return;
		}

		if (!this->isChecked())
		{
			setIconSize(QSize(ICON_UP_SIZE, ICON_UP_SIZE));
		}
	};

public slots:

	void buttonToggled( bool toggle )
	{
		if (!isEnabled())
		{
			return;
		}

		if( toggle )
		{
			setStyleSheet(QString::fromUtf8(
						"background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(59, 94, 25, 255), stop:1 rgba(59, 94, 25, 255));\n"
						"border-color: qlineargradient(spread:pad, x1:0.523, y1:1, x2:0.511, y2:0, stop:0 rgba(124, 124, 124, 255), stop:1 rgba(219, 219, 219, 255));\n"
						"border-width: 1px;\n"
						"border-style: inset;\n"
						"color: rgb(255, 255, 255);\n"
						""));
		}
		else
		{
			setStyleSheet(QString::fromUtf8(
						"background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(79, 79, 79, 255), stop:1 rgba(32, 32, 32, 255));\n"
						"border-color: qlineargradient(spread:pad, x1:0.523, y1:1, x2:0.511, y2:0, stop:0 rgba(124, 124, 124, 255), stop:1 rgba(219, 219, 219, 255));\n"
						"border-width: 1px;\n"
						"border-style: inset;\n"
						"color: rgb(255, 255, 255);\n"
						""));
			setIconSize(QSize(ICON_UP_SIZE, ICON_UP_SIZE));
		}
	}

	void setDisabledSkin()
	{
		setStyleSheet(QString::fromUtf8(
					"background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(59, 59, 59, 255), stop:1 rgba(22, 22, 22, 255));\n"
					"border-top-color: rgba(69, 69, 69, 255);\n"
					"border-left-color: rgba(69, 69, 69, 255);\n"
					"border-right-color: rgba(0, 0, 0, 0);\n"
					"border-bottom-color: rgba(0, 0, 0, 0);\n"
					"border-width: 1px;\n"
					"border-style: inset;\n"
					"color: rgb(100, 100, 100);\n"
					""));
	};

	void setEnabledSkin()
	{
		setStyleSheet(QString::fromUtf8(
					"background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(79, 79, 79, 255), stop:1 rgba(32, 32, 32, 255));\n"
					"border-color: qlineargradient(spread:pad, x1:0.523, y1:1, x2:0.511, y2:0, stop:0 rgba(124, 124, 124, 255), stop:1 rgba(219, 219, 219, 255));\n"
					"border-width: 1px;\n"
					"border-style: inset;\n"
					"color: rgb(255, 255, 255);\n"
					""));
	};

};

#endif
